package it.stasbranger.myproject.dao;

import it.stasbranger.myproject.domain.SuppliersHasRequests;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage SuppliersHasRequests entities.
 * 
 */
@Repository("SuppliersHasRequestsDAO")
@Transactional
public class SuppliersHasRequestsDAOImpl extends AbstractJpaDao<SuppliersHasRequests>
		implements SuppliersHasRequestsDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { SuppliersHasRequests.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new SuppliersHasRequestsDAOImpl
	 *
	 */
	public SuppliersHasRequestsDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsBySenddate
	 *
	 */
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsBySenddate(java.util.Date senddate) throws DataAccessException {

		return findSuppliersHasRequestsBySenddate(senddate, -1, -1);
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsBySenddate
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsBySenddate(java.util.Date senddate, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findSuppliersHasRequestsBySenddate", startResult, maxRows, senddate);
		return new LinkedHashSet<SuppliersHasRequests>(query.getResultList());
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsByPrimaryKey
	 *
	 */
	@Transactional
	public SuppliersHasRequests findSuppliersHasRequestsByPrimaryKey(Integer suppliersIdsuppliers, Integer requestsIdrequests) throws DataAccessException {

		return findSuppliersHasRequestsByPrimaryKey(suppliersIdsuppliers, requestsIdrequests, -1, -1);
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsByPrimaryKey
	 *
	 */

	@Transactional
	public SuppliersHasRequests findSuppliersHasRequestsByPrimaryKey(Integer suppliersIdsuppliers, Integer requestsIdrequests, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findSuppliersHasRequestsByPrimaryKey", suppliersIdsuppliers, requestsIdrequests);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsBySuppliersIdsuppliers
	 *
	 */
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsBySuppliersIdsuppliers(Integer suppliersIdsuppliers) throws DataAccessException {

		return findSuppliersHasRequestsBySuppliersIdsuppliers(suppliersIdsuppliers, -1, -1);
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsBySuppliersIdsuppliers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsBySuppliersIdsuppliers(Integer suppliersIdsuppliers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findSuppliersHasRequestsBySuppliersIdsuppliers", startResult, maxRows, suppliersIdsuppliers);
		return new LinkedHashSet<SuppliersHasRequests>(query.getResultList());
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsByRequestsIdrequests
	 *
	 */
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsByRequestsIdrequests(Integer requestsIdrequests) throws DataAccessException {

		return findSuppliersHasRequestsByRequestsIdrequests(requestsIdrequests, -1, -1);
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsByRequestsIdrequests
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsByRequestsIdrequests(Integer requestsIdrequests, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findSuppliersHasRequestsByRequestsIdrequests", startResult, maxRows, requestsIdrequests);
		return new LinkedHashSet<SuppliersHasRequests>(query.getResultList());
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsByPrice
	 *
	 */
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsByPrice(Integer price) throws DataAccessException {

		return findSuppliersHasRequestsByPrice(price, -1, -1);
	}

	/**
	 * JPQL Query - findSuppliersHasRequestsByPrice
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<SuppliersHasRequests> findSuppliersHasRequestsByPrice(Integer price, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findSuppliersHasRequestsByPrice", startResult, maxRows, price);
		return new LinkedHashSet<SuppliersHasRequests>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllSuppliersHasRequestss
	 *
	 */
	@Transactional
	public Set<SuppliersHasRequests> findAllSuppliersHasRequestss() throws DataAccessException {

		return findAllSuppliersHasRequestss(-1, -1);
	}

	/**
	 * JPQL Query - findAllSuppliersHasRequestss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<SuppliersHasRequests> findAllSuppliersHasRequestss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllSuppliersHasRequestss", startResult, maxRows);
		return new LinkedHashSet<SuppliersHasRequests>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(SuppliersHasRequests entity) {
		return true;
	}
}
